Imports System.Collections.Generic
Imports System.Linq
Imports System.Web

#Region "using"
Imports System.Data
Imports QUANLY.DTO
#End Region
Public Class PHIEUDATTOURDAO
	Inherits AbstractDAO
	Public Sub New(strPath As [String])
		MyBase.New(strPath)
	End Sub

	Public Function SelectAll() As DataSet
		Dim ds As DataSet
		Try
			ds = New DataSet()
			MyBase.sql = "usp_PHIEUDATTOUR_SelectAll"
			MyBase.FillDataSet(ds, "PHIEUDATTOUR")
			Return ds
		Catch e As System.Exception
			Throw New Exception(e.Message, e.InnerException)
		Finally
			MyBase.CleanUpObject()
		End Try
	End Function

	Public Function SelectByID(id As Integer) As DataSet
		Dim ds As DataSet
		Try
			ds = New DataSet()
			MyBase.sql = "usp_PHIEUDATTOUR_SelectByID"
			MyBase.InitializeCommand()
			MyBase.AddParameter("@ID", SqlDbType.Int, 1000, id)
			MyBase.FillDataSet(ds, "PHIEUDATTOUR")
			Return ds
		Catch e As System.Exception
			Throw New Exception(e.Message, e.InnerException)
		Finally
			MyBase.CleanUpObject()
		End Try
	End Function

	Public Function Insert(obj As PHIEUDATTOURDTO) As Boolean
        Try
            Dim kq As Boolean

            MyBase.sql = "usp_PHIEUDATTOUR_Insert"
            MyBase.InitializeCommand()
            MyBase.AddParameter("@IDNhanVien", SqlDbType.Int, 1000, obj.IDNhanVien)
            MyBase.AddParameter("@IDTour", SqlDbType.Int, 1000, obj.IDTour)
            MyBase.AddParameter("@HinhThucThanhToan", SqlDbType.NVarChar, 1000, obj.HinhThucThanhToan)
            MyBase.AddParameter("@NgayLapPhieu", SqlDbType.Date, 1000, obj.NgayLapPhieu)
            MyBase.AddParameterWithDirection("@ID", SqlDbType.Int, 10)

            kq = ExecuteStoredProcedure()
            obj.ID = Integer.Parse(MyBase.GetParamValue("@ID").ToString())

            Return kq
        Catch
            Return False
        End Try
	End Function

	Public Function Update(obj As PHIEUDATTOURDTO) As Boolean
		Try
			MyBase.sql = "usp_PHIEUDATTOUR_Update"
			MyBase.InitializeCommand()
			MyBase.AddParameter("@ID", SqlDbType.Int, 1000, obj.ID)
			MyBase.AddParameter("@IDNhanVien", SqlDbType.Int, 1000, obj.IDNhanVien)
            MyBase.AddParameter("@IDTour", SqlDbType.Int, 1000, obj.IDTour)
            MyBase.AddParameter("@HinhThucThanhToan", SqlDbType.NVarChar, 1000, obj.HinhThucThanhToan)
            MyBase.AddParameter("@NgayLapPhieu", SqlDbType.Date, 1000, obj.NgayLapPhieu)
			Return ExecuteStoredProcedure()
		Catch
			Return False
		End Try
	End Function

	Public Function Delete(id As Integer) As Boolean
		Try
			MyBase.sql = "usp_PHIEUDATTOUR_Delete"
			MyBase.InitializeCommand()
			MyBase.AddParameter("@ID", SqlDbType.Int, 1000, id)
			Return ExecuteStoredProcedure()
		Catch
			Return False
		End Try
	End Function

	Public Function SelectByIDNhanVien(idnhanvien As Integer) As DataSet
		Dim ds As DataSet
		Try
			ds = New DataSet()
			MyBase.sql = "usp_PHIEUDATTOUR_SelectByIDNhanVien"
			MyBase.InitializeCommand()
			MyBase.AddParameter("@IDNhanVien", SqlDbType.Int, 1000, idnhanvien)
			MyBase.FillDataSet(ds, "PHIEUDATTOUR")
			Return ds
		Catch e As System.Exception
			Throw New Exception(e.Message, e.InnerException)
		Finally
			MyBase.CleanUpObject()
		End Try
	End Function

	Public Function SelectByIDTour(idtour As Integer) As DataSet
		Dim ds As DataSet
		Try
			ds = New DataSet()
			MyBase.sql = "usp_PHIEUDATTOUR_SelectByIDTour"
			MyBase.InitializeCommand()
			MyBase.AddParameter("@IDTour", SqlDbType.Int, 1000, idtour)
			MyBase.FillDataSet(ds, "PHIEUDATTOUR")
			Return ds
		Catch e As System.Exception
			Throw New Exception(e.Message, e.InnerException)
		Finally
			MyBase.CleanUpObject()
		End Try
	End Function

End Class
